<template>
  <div>
    <a-modal :visible="visible" @ok="handleOK" @cancel="visible = false">
      <a-tree
        v-model="checked"
        checkable
        :auto-expand-parent="autoExpandParent"
        :tree-data="catalogs"
      />
    </a-modal>
  </div>
</template>
<script>
export default {
  computed: {
    catalogs() {
      return this.$store.state.tmodel.catalogModelTree;
    },
  },
  data() {
    return {
      checked: [],
      autoExpandParent: true,
      visible: false,
      fun: null,
      owner: null,
    };
  },
  methods: {
    Show(fun, owner) {
      this.fun = fun;
      this.owner = owner;
      this.visible = true;
    },
    handleOK() {
      let cache = this.$store.state.tmodel.tmodelCache;
      let models = [];
      if (this.checked) {
        this.checked.forEach((c) => {
          let m = cache[c];
          if (m) {
            models.push(m);
          }
        });
      }
      if (this.fun && this.owner) {
        this.fun(models, this.owner);
        this.visible = false;
      }
    },
  },
};
</script>